
import React, { useRef, useState } from "react";

export default function UploadCard({ onUpload }) {
  const [name, setName] = useState("MyAsset");
  const fileRef = useRef(null);

  const handleSubmit = () => {
    const file = fileRef.current?.files?.[0];
    if (!file) return alert("请先选择 CSV 文件");
    onUpload(file, name);
  };

  return (
    <div className="bg-white rounded-xl shadow p-6">
      <h2 className="text-lg font-semibold mb-4">1. 上传收益数据</h2>
      <p className="text-sm text-gray-600 mb-4">CSV 格式：两列 date & return（% 或小数均可）</p>
      <input
        className="block w-full text-sm text-gray-700 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100 mb-3"
        type="file"
        accept=".csv"
        ref={fileRef}
      />
      <input
        className="w-full mb-3 px-3 py-2 border rounded"
        placeholder="资产名称"
        value={name}
        onChange={(e) => setName(e.target.value)}
      />
      <button
        onClick={handleSubmit}
        className="w-full bg-blue-600 text-white py-2 rounded hover:bg-blue-700"
      >
        开始分析
      </button>
    </div>
  );
}
